package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;

import Controller.ComplaintSubmissionController;
import Controller.DBcontroller;
import Entity.Complaint;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;

/**
 * this is the GUI complaint section for the customer. it has only two buttons for viewing complaint and submit a new one.
 * @author Moran Abilea
 *
 */
public class CustomerGUI extends JFrame {

	private JPanel contentPane;
	/**
	 * is the constructor. it has two listers for each button and transfer us to the righ GUI.
	 */
	public CustomerGUI() {
		setTitle("Customer Complaints Window");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnOpenMyComplaints = new JButton("Open my complaints");
		btnOpenMyComplaints.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				close();
				CustomerComplaintViewBoundary openview=new CustomerComplaintViewBoundary(ComplaintSubmissionController.getCustomerComplaints(DBcontroller.getLoggedIn()));
				openview.setVisible(true);
			}
		});
		btnOpenMyComplaints.setBounds(229, 112, 182, 37);
		contentPane.add(btnOpenMyComplaints);
		
		JButton btnSubmitNewComplaint = new JButton("Submit new complaint");
		btnSubmitNewComplaint.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				close();
				SubmitComplaintBoundary opensubmit=new SubmitComplaintBoundary();
				opensubmit.setVisible(true);
			}
		});
		btnSubmitNewComplaint.setBounds(10, 112, 182, 37);
		contentPane.add(btnSubmitNewComplaint);
		
		JLabel lblWelcomeToComplaints = new JLabel("Welcome to complaints Section!");
		lblWelcomeToComplaints.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblWelcomeToComplaints.setBounds(97, 11, 279, 20);
		contentPane.add(lblWelcomeToComplaints);
		
		JLabel lblPleaseSelectYour = new JLabel("please select your action");
		lblPleaseSelectYour.setBounds(147, 69, 197, 14);
		contentPane.add(lblPleaseSelectYour);
	}
	
	public void close()
	{
		WindowEvent windowclose=new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
		Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(windowclose);
	}
}
